package cn.lixu.system.controller;

import cn.lixu.basic.util.PageList;
import cn.lixu.basic.util.JsonResult;
import cn.lixu.system.domain.Systemdictionarytype;
import cn.lixu.system.query.SystemdictionarytypeQuery;
import cn.lixu.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //controller层  返回的是json格式数据
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;


    /**
     * 查询全部
     *
     * @return
     */
    @GetMapping
    public List<Systemdictionarytype> loadAll() {
        return systemdictionarytypeService.loadAll();
    }

    /**
     * 查询一个
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarytype loadById(@PathVariable("id") Long id) {
        return systemdictionarytypeService.loadById(id);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public JsonResult deleteById(@PathVariable("id") Long id) {
        try {
            systemdictionarytypeService.remove(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.me().setMsg("删除失败");
        }
    }

    /**
     * @param
     * @return
     */
    @PutMapping
    public JsonResult addAndUpdate(@RequestBody Systemdictionarytype systemdictionarytype) {
        try {
            if (systemdictionarytype.getId() == null) {
                systemdictionarytypeService.save(systemdictionarytype);
            } else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.me().setMsg("操作失败");
        }
    }

    /**
     * 分页数据
     *
     * @param
     * @return
     */
    @PostMapping
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery) {
        return systemdictionarytypeService.queryPage(systemdictionarytypeQuery);

    }

    /**
     * 批量删除
     * @param
     * @return
     */
    @PatchMapping
    public JsonResult patchDel(@RequestBody List<Long> ids) {
        try {
            systemdictionarytypeService.patchDel(ids);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.me().setMsg("删除失败");
        }
    }
}

